import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import prismjs from 'vite-plugin-prismjs';
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import {ElementPlusResolver} from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    vue(),
    prismjs({
      languages: 'all',
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      components:'@/components'
    }
  },
  server: {
    host:'0.0.0.0',
    port:8081,
    //配置到"http://localhost:8080"的跨域

    proxy: {
      "/api": {
        // 代理目标地址
        target: "http://localhost:8080",
        // 是否改变原地址
        changeOrigin: true,
        // 重写路径
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    }
}
})
